#!/bin/sh

if [ "$INWINDOW" != "true" ]
then
	export INWINDOW=true
	Terminal -t "Instant Preview Installation" "$0"
	exit 0
fi

SRC_DIR=`/bin/dirname "$0"`
BIN_DIR="/boot/apps/Gopherwood"
ADD_ON_DIR="/boot/home/config/add-ons/Tracker"
PREFS="/boot/home/config/settings/Gopherwood/InstantPreview.pref"

MACHINE=`uname -m`

echo -n "Delete unused files..."
case "$MACHINE" in
	BePC)
		CPU=x86
		rm -f "$SRC_DIR"/ppc/InstantPreview
		rm -f "$SRC_DIR"/ppc/InstantPreview-V
		;;
	*)
		CPU=ppc
		rm -f "$SRC_DIR"/x86/InstantPreview
		rm -f "$SRC_DIR"/x86/InstantPreview-V
		;;
esac
echo "done"

echo -n "Delete old preference file..."
rm -f "$PREFS"
echo "done"

echo -n "Install application..."
mkdir -p "$BIN_DIR"
mv -f "$SRC_DIR/$CPU/InstantPreview" "$BIN_DIR/InstantPreview"
mimeset -F -all "$BIN_DIR/InstantPreview"
echo "done"

echo -n "Install Tracker add-on..."
mkdir -p "$ADD_ON_DIR"
mv -f "$SRC_DIR/$CPU/InstantPreview-V" "$ADD_ON_DIR/InstantPreview-V"
mimeset -F -all "$ADD_ON_DIR/InstantPreview-V"
echo "done"

echo
echo "*** If you installed old version of \"Instant Preview\", delete old binary. ***"
echo

if [ "$INWINDOW" != "" ]
then
	echo -n "(Press Enter to close this window.) "
	read
fi
